<template>
	<view class="container">
		
		
		<!-- 第一步 -->
		<view v-if="infopart == 0" class="doc-info-head">
			<view class="doc-info-head-t">
				<view class="doc-info-head-tTitle">
					<text class="doc-info-head-tTitleNav">个人信息</text>
				</view>
				<view class="doc-info-head-tname">
					<text class="doc-info-head-tTxt">姓名</text>
					<view class="doc-info-head-tipt">
						<input class="doc-info-head-tchioce" type="text" v-model="docname" placeholder-style="color:#0E1B52" placeholder="请输入姓名" />
					</view>
				</view>
				<view class="doc-info-head-tname">
					<text class="doc-info-head-tTxt">科室</text>
					<view class="doc-info-head-tipt" @click="openpicker(2)">
						<text class="doc-info-head-tchioce">{{infoDepart}}</text>
						<view class="doc-info-head-tchioceImg">
							<image src="../../static/icon_right.png" mode="widthFix"></image>
						</view>
						<!-- <input type="text" value="" v-model="hos" @click="openpicker" placeholder-style="color:#bcc1cc" placeholder="请输入姓名" /> -->
					</view>
				</view>
				<view class="doc-info-head-tname">
					<text class="doc-info-head-tTxt">职称</text>
					<view class="doc-info-head-tipt" @click="openpicker(3)">
						<text class="doc-info-head-tchioce">{{infoName}}</text>
						<view class="doc-info-head-tchioceImg">
							<image src="../../static/icon_right.png" mode="widthFix"></image>
						</view>
						<!-- <input type="text" value="" v-model="hos" @click="openpicker" placeholder-style="color:#bcc1cc" placeholder="请输入姓名" /> -->
					</view>
				</view>
			</view>
			<view class="doc-info-head-intr">
				<view class="doc-info-head-tTitle">
					<text class="doc-info-head-tTitleNav">个人简介</text>
				</view>
				<view class="doc-info-head-intrmore">
					<textarea class="doc-info-head-intrmoreTxt" v-model="intro" maxlength="300" placeholder-style="color:#BCC1CC" placeholder="请输入个人简介" />
				</view>
			</view>
		</view>
		
		
		<view v-else class="doc-info-zj">
			<view class="doc-info-zj-pic">
				 <image v-if="imageh == ''" src="../../static/img_head2.png"  @click="chooseImg(0)"></image>
				 <image v-else :src="imageh"  @click="chooseImg(0)"></image>
			</view>
			<view class="doc-info-zj-IDcard">
				<text class="doc-info-zj-IDcardTitle">身份证件</text>
				<view class="line"></view>
				<view class="doc-info-zj-IDcardcon IDcardcon-al">
					<view class="doc-info-zj-IDcardconItem">
						<image v-if="imagea == ''" src="../../static/img_card_b.png" mode="widthFix" @click="chooseImg(1)"></image>
						<image v-else :src="imagea" mode="widthFix" @click="chooseImg(1)"></image>
					</view>
					<view class="doc-info-zj-IDcardconItem">
						<image v-if="imageb == ''" src="../../static/img_card_a.png" mode="widthFix" @click="chooseImg(2)"></image>
						<image v-else :src="imageb" mode="widthFix" @click="chooseImg(2)"></image>
					</view>
				</view>
			</view>
			<view class="doc-info-zj-IDcard other">
				<text class="doc-info-zj-IDcardTitle">证书图片</text>
				<view class="line"></view>
				<view class="doc-info-zj-IDcardcon">
					<view class="doc-info-zj-zsItem" v-if="imageclist.length>0" v-for="(item,index) in imageclist" :key="index">
						<image :src="item"  @click="chooseImg(3)"></image>
					</view>
					<view class="doc-info-zj-zsItem">
						<image :src="imagec == ''?'../../static/icon_upd.png':'imagec'" mode="widthFix" @click="chooseImg(3)"></image>
					</view>
				</view>
			</view>
		</view>
		
		
		<view class="per-man-add">
			<view class="per-man-addNav" v-if="infopart == 0" @click="nextType">
				<text class="per-man-addText">下一步</text>
			</view>
			<view class="per-man-addNav" v-else @click="submit">
				<text class="per-man-addText">提交</text>
			</view>
		</view>
		<w-picker
			:visible.sync="infoDepartpart"
			default-type="name"
			:default-props="defaultProps"
			mode="selector"
			:options="infoDepartList"
			@confirm="changehos($event,2)"
		></w-picker>
		<w-picker
			:visible.sync="infoNamepart"
			default-type="name"
			:default-props="defaultProps"
			mode="selector"
			:options="infoNameList"
			@confirm="changehos($event,3)"
		></w-picker>
	</view>
</template>

<script>
	import app from '../../App.vue'
	 export default {
	    data() {
	      return {
			infopart:0,  //个人信息或上传照片
			// infoHos:'请选择医院',  //医院
			docname:'',				//姓名
			intro:'',				//个人简介
			infoDepart:'请选择科室',  //科室
			infoDepartid:'',		//科室id
			infoName:'请选择职称',  //职称
			infoHospart:false,  //医院显示
			infoDepartpart:false,  //科室显示
			infoNamepart:false,  //医院显示
			defaultProps:{"label":"name","value":"id"},
			infoDepartList:[],			//科室列表
			infoNameList:[
				{
					name:'执业医师'
				},
				{
					name:'主治医师'
				},
				{
					name:'副主任医师'
				},
				{
					name:'主任医师'
				}
			],
			imageh:'',		//身份证正面
			imagehUrl:'',	//身份证正面
			imagea:'',		//身份证正面
			imageaUrl:'',	//身份证正面上传
			imageb:'',		//身份证反面
			imagebUrl:'',	//身份证反面上传
			imageclist:[],//荣誉
			imagecUrllist:[],//荣誉上传
			imagec:'',		//荣誉
			imagecUrl:'',	//荣誉上传
			}
	    },
		onLoad() {
			this.choosekeshi()
		},
	    methods: {
			openpicker(num){				//打开选择
				if(num == 2){
					this.infoDepartpart = true
				}else if(num == 3){
					this.infoNamepart = true
				}
			},
			changehos(e,num){				//选择项
				if(num == 2){
					this.infoDepart = e.obj.name
					this.infoDepartid = e.obj.id
				}else if(num == 3){
					this.infoName = e.obj.name
					console.log(e.obj)
				}
			},
			choosekeshi(){ 					//获取科室列表
				let that = this,
				data = {
					keyword:'',
					limit:''
				}
				app.post('api/department/lis',data).then(res=>{
					if(res.code == 1){
						that.infoDepartList = res.data
					}if(res.code = 0){
						uni.showToast({
							title:res.msg,
							icon:'none',
							mark:true
						})
					}
				}).catch(err=>{
					uni.showToast({
						title:res.msg,
						icon:'none',
						mark:true
					})
				})
			},
			nextType(){					//下一步
				let that = this
				if(this.docname == ''|| this.intro == '' || this.infoDepartid == ''||this.infoNamem ==''){
					uni.showToast({
						title:'请将信息填写完整',
						icon:'none',
						mark:true
					})
				}else{
					uni.showLoading({
						title:'加载中',
						success() {
							uni.hideLoading()
							that.infopart = 1
						}
					})
				}
			},
			chooseImg(num){				//上传图片
				let that = this
				uni.chooseImage({
					count:1,
					sizeType:['original', 'compressed'],
					sourceType:['album','camera'],
					success(res) {
						console.log(res)
						 var tempFilePaths = res.tempFilePaths;
						 console.log(tempFilePaths)
						 const baseUrl = 'http://tanggu-hospital.t.brotop.cn/'
						 let url = 'api/common/upload';
						 uni.uploadFile({
						     url: baseUrl+url, //仅为示例，非真实的接口地址
						     filePath: tempFilePaths[0],
						     name: 'file',
							 header: {
									'token': uni.getStorageSync('token')
								},
						     formData: {
								 filetype: 'image'
						     },
						     success: (res) => {
								 let data = JSON.parse(res.data)
								 if(num == 0){
									 that.imageh = data.data.fullurl				//显示
									 that.imagehUrl = data.data.url						//上传
								 }else if(num == 1){
									 that.imagea = data.data.fullurl				//显示
									 that.imageaUrl = data.data.url						//上传
									 console.log(data.data)
								 }else if(num == 2){
									 that.imageb = data.data.fullurl				//显示
									 that.imagebUrl = data.data.url					//上传
								 }else if(num == 3){
									 that.imageclist.push(data.data.fullurl)		//显示
									 that.imagecUrllist.push(data.data.url)					//上传
								 }
						     }
						 });
					}
				})
			},
			submit(){
				let that = this,
				cert_images = that.imagecUrllist.toString(),
				data = {
					nickname:that.docname,
					department_id:that.infoDepartid,
					title:that.infoName,
					bio:that.intro,
					id_no1_image:that.imageaUrl,
					id_no2_image:that.imagebUrl,
					cert_images:cert_images
				}
				app.post('api/user/submitProfile',data).then(res=>{
					if(res.code == 1){
						uni.showLoading({
							title:'加载中',
							success() {
								setTimeout(function(){
									uni.hideLoading({
										success:res=>{
											uni.navigateTo({
												url:'/pages/doc/apply?status=0'
											})
										}
									})
								},1300)
							}
						})
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				}).catch(err=>{
					uni.showToast({
						title:err.msg,
						icon:'none'
					})
				})
			}
		}
	}
</script>

<style>
	@import url("../../common/docinfo.css");
</style>
